package com.dl.mall;

import com.alibaba.fastjson.JSON;
import com.dl.mall.entity.Page;
import com.dl.mall.entity.Product;
import com.dl.mall.entity.vo.HistoryOrderVo;
import com.dl.mall.entity.vo.OrderCartVo;
import com.dl.mall.info.BrandInfo;
import com.dl.mall.mapper.OrderMapper;
import com.dl.mall.mapper.ProductMapper;
import com.dl.mall.service.user.OrderService;
import com.dl.mall.service.user.ProductService;
import com.dl.mall.utils.PageUtils;
import com.github.pagehelper.PageHelper;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import javax.annotation.Resource;
import java.lang.reflect.Array;
import java.math.BigDecimal;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;

/**
 * @author DL
 * @create 2022-03-13 17:15
 */
@SpringBootTest
@RunWith(SpringRunner.class)
public class testOrder {

    @Resource
    OrderMapper orderMapper;

    @Resource
    OrderService orderService;
/*

    @Test
    public void queryProduct(){
        List<HashMap<String, Object>> list = orderMapper.queryHistoryOrderInfo("awec103401");
        System.out.println("list = " + list);
        ArrayList<HistoryOrderVo> historyOrderVoList = new ArrayList<>();
        list.forEach(item -> {
            System.out.println("item = " + item);
            HistoryOrderVo historyOrderVo = new HistoryOrderVo();
            historyOrderVo.setOrderId((Long) item.get("order_id"));
            historyOrderVo.setTotalAmount((BigDecimal) item.get("total_amount"));
            historyOrderVo.setOrderState((Integer) item.get("order_state"));
            historyOrderVo.setCreateTime((Timestamp) item.get("create_time"));
            historyOrderVo.setUpdateTime((Timestamp) item.get("update_time"));

            String productIdStr = (String) item.get("product_id");
            String[] productArr = productIdStr.split(",");

            String specsImgStr = (String) item.get("specs_img");
            String[] specsImgArr = specsImgStr.split(",");

            String nameStr = (String) item.get("name");
            String[] nameArr = nameStr.split(",");

            String productSpecsStr = (String) item.get("product_specs");
            String[] productSpecsArr = productSpecsStr.split(",");

            String priceStr = (String) item.get("price");
            String[] priceArr = priceStr.split(",");

            String totalStr = (String) item.get("total");
            String[] totalArr = totalStr.split(",");

            ArrayList<OrderCartVo> historyCartVoList = new ArrayList<>();
            for (int i = 0; i < productArr.length; i++) {
                OrderCartVo orderCartVo = new OrderCartVo();
                orderCartVo.setProductId(productArr[i]);
                orderCartVo.setSpecsImg(specsImgArr[i]);
                orderCartVo.setName(nameArr[i]);
                orderCartVo.setProductSpecs(productSpecsArr[i]);
                orderCartVo.setPrice(new BigDecimal(priceArr[i]));
                orderCartVo.setTotal(Integer.parseInt(totalArr[i]));
                historyCartVoList.add(orderCartVo);
                historyOrderVo.setHistoryCartVoList(historyCartVoList);
            }

            historyOrderVoList.add(historyOrderVo);
        });

        historyOrderVoList.forEach(System.out::println);

    }
*/


/*    @Test
    public void queryProduct(){

        PageHelper.startPage(2, 3);
        List<Product> list = productMapper.queryProduct();
        System.out.println("list = " + list);

        Page<Product> page = (Page<Product>) PageUtils.getPage(list);

        String string = JSON.toJSONString(page);
        System.out.println("string = " + string);
        System.out.println("page = " + page);
    }*/




}
